package org.com.ashen.web.timer;


import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.fcibook.quick.http.QuickHttp;
import org.apache.http.entity.ContentType;
import org.com.ashen.web.constant.CommonUtils;

import org.com.ashen.service.util.FileUtil;
import java.io.File;
import java.io.IOException;
import java.util.Timer;

import javax.servlet.ServletContextEvent;
import javax.servlet.ServletContextListener;

public class SysContextListener implements ServletContextListener {

	public void contextInitialized(ServletContextEvent event) {
		System.out.println("aaa启动了");
		String client_id = "CB524068C8BF6FF86BEBC45CB3599A94";
		String client_secret = "C70FA1FCB310C3001A82AC96FB152F27";
		String refresh_token = "55b696e3-91ae-42d6-9851-6cc351c250b1";
		String url = "https://dopen.weimob.com/fuwu/b/oauth2/token?grant_type=refresh_token&client_id=" + client_id + "&client_secret=" + client_secret + "&refresh_token=" + refresh_token;
		String accessToke = new QuickHttp()
				.url(url)
				.setContentType(ContentType.APPLICATION_JSON)
				.addHeader("charset", "utf-8")
				.post()
				.text();
		JSONObject jsonObject1 = new JSONObject();
		jsonObject1 = JSON.parseObject(accessToke);
		JSONObject jsonObject = new JSONObject();
		jsonObject.put("weimengAccessToken", jsonObject1.getString("access_token"));
		String jsonString = JSON.toJSONString(jsonObject);
		try {
			FileUtil.touch(new File(CommonUtils.FILE_PATH));
			FileUtil.genModuleTplClear(CommonUtils.FILE_PATH, jsonString);
		} catch (IOException e) {
			e.printStackTrace();
		}
	}
 
	public void contextDestroyed(ServletContextEvent event) {

	}
 
}